#!/usr/bin/env python3
import sys
import math
import os, time, random
import json
from multiprocessing import Pool

def recover_back_up(src_task_file, processed_rest_dir):
    fp = open(src_task_file, "r")
    for line in fp.readlines():
        subj_name = line.replace("\n", "")
        subj_name = subj_name.strip()

        sud_dir = os.path.join(processed_rest_dir, subj_name)
        surf_dir = os.path.join(sud_dir, 'surf')
        surf_qc_dir = os.path.join(sud_dir, 'surf_origin')

        if os.path.exists(surf_qc_dir):
            rm_cmd = 'rm -rf ' + surf_dir
            print('[CMD]: %s' % (rm_cmd))
            os.system(rm_cmd)

        cp_cmd = 'mv ' + surf_qc_dir + ' ' + surf_dir
        print('#' * 30)
        print('[CMD]: %s\n' % cp_cmd)
        os.system(cp_cmd)

if __name__=='__main__':
    project_dir = '/home/liang/Projects/ASD_QC'
    symbol      = "OHSU"
    sub_type    = "ASD"
    list_file   = 'variability_list_' + sub_type + '_' + symbol + '.txt'

    list_dir = os.path.join(project_dir, 'Lists')
    src_task_file = os.path.join(list_dir, list_file)
    processed_rest_dir = os.path.join(project_dir, 'DataProcessed/rest')

    recover_back_up(src_task_file, processed_rest_dir)
